package Views.TableModels;

import Models.*;
import javax.swing.table.*;
import java.util.ArrayList;

/**
 * @author Morten
 */
public class EmployeeTableModel extends DefaultTableModel
{
	private ArrayList<Employee> employees;

	public EmployeeTableModel()
	{
		this.employees = new ArrayList<Employee>();
	}

	public EmployeeTableModel(ArrayList<Employee> employees)
	{
		this.employees = employees;
	}

	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}

	public void setData(ArrayList<Employee> employees)
	{
		this.employees = employees;
		fireTableDataChanged();
	}

	public ArrayList<Employee> getData()
	{
		return this.employees;
	}

	@Override
	public int getColumnCount()
	{
		return 3;
	}

	@Override
	public int getRowCount()
	{
		if(this.employees == null)
		{
			return 0;
		}
		else
		{
			return this.employees.size();
		}
	}

	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Navn";
				break;
			case 2:
				columnName = "Afdeling";
				break;

		}
		return columnName;
	}

	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.employees.get(row).getId();
				break;
			case 1:
				value = this.employees.get(row).getName();
				break;
			case 2:
				if(this.employees.get(row).getLocation() == Location.LumberYard)
				{
					value = "Trælasthandel";
				}
				else
				{
					value = "Byggemarked";
				}
				break;

		}

		return value;
	}
}